import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from 'src/database/mysql/entity/user.entity';
import { CreateUserDto } from './dto/create-user.dto';
@Injectable()
export class UserService {
  constructor(
    @InjectRepository(User)
    private readonly userRepository: Repository<User>,
  ) {}

  findOne(id: number): Promise<User | null> {
    return this.userRepository.findOneBy({ id });
  }

  async findAll(): Promise<{ list: User[]; total: number }> {
    const list = await this.userRepository.find();
    const total = await this.userRepository.count();
    return {
      list,
      total,
    };
  }
  create(CreateUserDto: CreateUserDto): Promise<User> {
    return this.userRepository.save(CreateUserDto);
  }
}
